package com.example.framework;

import org.netbeans.jemmy.ClassReference;
import org.netbeans.jemmy.operators.JFrameOperator;

import java.util.Properties;

public class HelperManager {
   private Properties properties;
    private FolderHelper folderHelper;
    private JFrameOperator mainFrame;
    private MenuHelper menuHelper;

    public HelperManager(Properties properties) {
        this.properties = properties;
    }

    public FolderHelper getFolderHelper() {
        if (folderHelper == null){
            folderHelper = new FolderHelper(this);
        }
        return folderHelper;
    }

    public JFrameOperator getApplication() {
        if (mainFrame == null){
            try {
                new ClassReference(properties.getProperty("applicationMainClass")).startApplication();
                mainFrame = new JFrameOperator("jAddressBook");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return mainFrame;
    }

    public MenuHelper getMenuHelper() {
        if (menuHelper == null){
            menuHelper = new MenuHelper(this);
        }
        return menuHelper;
    }

    public void stop(){
        getApplication().requestClose();
    }
}

